<?php
/** .-------------------------------------------------------------------
 * |  Software: [HDCMS framework]
 * |      Site: www.hdcms.com
 * |-------------------------------------------------------------------
 * |    Author: 向军 <2300071698@qq.com>
 * |    WeChat: aihoudun
 * | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

namespace web\admin\controller;

class Typeattr extends Common{
    //动作
    private $db;
    public function __construct()
    {
        $this->db=new \system\model\Typeattr();
    }

    public function index(){
		//载入属性列表
        $tid=q('get.tid',0,'inteval');
        //p($tid);die;
        $data=$this->db->getAll();
        $typename=Db::table('type')->where('tid',$tid)->first();
        $typename=$typename['tname'];
        View::with('tname',$typename);
        //p($data);die;
        View::with('tid',$tid)->with('data',$data)->make();
	}
    //属性添加
    public function add(){
        $tid=q('tid',0,'intval');
        if(IS_POST){
            if($this->db->store()){
                message('添加成功',"index&tid={$tid}",'success');
            }else{
                message($this->db->getError(),'back','error');
            }
        }
        //p($_POST);die;
        View::make();
    }
    //属性修改
    public function edit(){
        if(IS_POST){
          $tid=$_POST['tid'];
            if($this->db->xiugai()){
                message('修改成功',"index&tid={$tid}",'success');
            }else{
                message($this->db->getError(),'back','error');
            }
        }
        //获取旧数据
        $taid=q('get.taid',0,'intval');
        $olddata=$this->db->where('taid',$taid)->first();
        //p($olddata);die;
        View::with('olddata',$olddata)->make();
    }
    //删除属性
    public function del(){
        $taid=q('get.taid',0,'intval');
//        $taid=$_POST['taid'];
        $tid=q('get.tid',0,'intval');
        $this->db->where('taid',$taid)->delete();
        message('删除成功',u("index&tid={$tid}"),'success');
    }
}
